<?php

namespace app\admin\model;

use app\common\model\Balance as BaseModel;
use app\admin\model\User as UserModel;
class Balance extends BaseModel
{
    /**
     * 获取器 字段action_text
     */
    public function getActionTextAttr($value, $data){
        return self::$ACTION[$data['action']]??'';
    }


    public function searchUserIdAttr($query, $value){
        if ($value){
            $query->where('user_id',$value);
        }
    }


    /**
     * 搜索器 字段phone
     */
    public function searchPhoneAttr($query, $value){
        if ($value) {
            $userIds = UserModel::where('phone','like',$value.'%')->column('id');
            $userIds = $userIds?:[0];
            $query->where('user_id','in',$userIds);
        }
    }

    /**
     * 搜索器 字段action
     */
    public function searchActionAttr($query, $value){
        if ($value){
            $query->where('action',$value);
        }
    }

    /**
     * 搜索器 查询时间范围
     */
    public function searchCreateTimeAttr($query, $value)
    {
        if ($value) {
            $query->whereTime('create_time', 'between', explode(' - ', $value));
        }
    }
}